package com.franklin.ideaplugin.api.json.fastjson2;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import com.franklin.ideaplugin.api.beans.EnumClass;
import com.franklin.ideaplugin.api.beans.IPresentableJsonBean;

import java.lang.reflect.Type;
import java.util.List;

/**
 * @author Ye Junhui
 * @since 2023/7/6
 */
public class PresentableJsonBeanSerializer implements ObjectWriter<String> {
    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        if (object == null) {
            jsonWriter.writeNull();
            return;
        }

        if (object instanceof IPresentableJsonBean) {
            IPresentableJsonBean presentableJsonBean = (IPresentableJsonBean) object;
            jsonWriter.writeString(presentableJsonBean.presentableString());
            return;
        }
        jsonWriter.writeNull();
    }
}
